Skip to content

fix: unify Anthropic/Claude model detection in ProviderTransform#20414

Closed
bussnet wants to merge 2 commits intoanomalyco:devfrom
bussnet:fix/consistent-anthropic-model-detection
Closed

fix: unify Anthropic/Claude model detection in ProviderTransform#20414
bussnet wants to merge 2 commits intoanomalyco:devfrom
bussnet:fix/consistent-anthropic-model-detection

Conversation

@bussnet
Copy link
Copy Markdown

@bussnet bussnet commented Apr 1, 2026

Summary

  • Extracts a single isClaudeModel() helper in transform.ts to replace three inconsistent detection strategies for identifying Claude/Anthropic models
  • Fixes 400 "assistant message prefill" errors when Claude models are routed through OpenAI-compatible proxies

Problem

ProviderTransform uses three different conditions to detect Anthropic/Claude models, and they disagree:

Transform Condition Effect
Empty content stripping api.npm === "@ai-sdk/anthropic" Strict — npm package only
Tool call ID scrubbing api.id.includes("claude") Name-based
Prompt caching providerID || api.id || model.id || api.npm Broad — checks everything

When a Claude model is accessed through an OpenAI-compatible proxy (@ai-sdk/openai-compatible), the model name may contain "claude" but the npm package is not @ai-sdk/anthropic. This causes caching and tool-ID scrubbing to activate while empty-content stripping does not. Empty assistant messages survive, get cache metadata attached, and Anthropic rejects them as invalid prefill.

Fix

Single isClaudeModel(model) function used at all three sites:

function isClaudeModel(model: Provider.Model): boolean {
  return (
    model.providerID === "anthropic" ||
    model.providerID === "google-vertex-anthropic" ||
    model.api.id.includes("anthropic") ||
    model.api.id.includes("claude") ||
    model.id.includes("anthropic") ||
    model.id.includes("claude") ||
    model.api.npm === "@ai-sdk/anthropic" ||
    model.api.npm === "@ai-sdk/google-vertex/anthropic" ||
    model.api.npm === "@ai-sdk/amazon-bedrock"
  )
}

Testing

  • No new errors introduced (5 pre-existing switch clause lint warnings unchanged)
  • Single file change: packages/opencode/src/provider/transform.ts

Extract isClaudeModel() helper to replace three inconsistent detection
strategies that used different conditions to identify Claude models.

The empty-content stripping (L56) only checked api.npm while caching
(L282) and tool-ID scrubbing (L76) used broader name-based checks.
This mismatch caused 400 prefill errors when Claude models were routed
through OpenAI-compatible proxies — caching applied but the required
empty-content stripping did not.
@github-actions github-actions bot added the needs:compliance This means the issue will auto-close after 2 hours. label Apr 1, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

The test spread from anthropicModel which has id containing 'claude',
making isClaudeModel() correctly detect it as Claude despite the
overridden providerID and api fields.
@bussnet
Copy link
Copy Markdown
Author

bussnet commented Apr 1, 2026

Reson for the failing e2e-tests: OPENCODE_API_KEY is required when OPENCODE_E2E_REQUIRE_PAID=true — missing secret, not related to this change

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Apr 1, 2026
@github-actions github-actions bot closed this Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant